<script setup>
import { ref } from 'vue'

// defineProps({
//   msg: String
// })

const count = ref(0)
// const t = 5.889134761230013e-39
// alert(parseFloat(t.toFixed(2)))
// alert(hexToSingle('00004106'))
// alert(Math.round(hexToSingle('00004106')))
// alert(Math.round(hexToSingle('41BF0900')))

</script>

<template>
  <h2>4字节转浮点数</h2>
  <div>
    <div>4字节：<input v-model="hexStr" @keyup.enter="calculate">
      <a-button type="primary" @click="calculate">计算</a-button>
    </div>
    <div v-if="enterHexStr.length === 8">
      <div>转浮点数：{{hexToSingle(enterHexStr)}}</div>
      <div>四舍五入整数：{{Math.round(hexToSingle(enterHexStr))}}</div>
    </div>
    <div v-else>
      请输入长度为8的字节字符串
    </div>
  </div>

  <h2>摘要加密</h2>
  <crypto></crypto>
  
  
</template>
<script>

export default {
  data() {
    return {
      hexStr: '',
      enterHexStr: ''
    }
  },
  mounted() {
  },
  methods: {
    calculate() {
      this.enterHexStr = this.hexStr
    },
    hexToSingle (num) {
      var a = num;
      var b = parseInt(a,16);
      var s = (b&0x80000000) ? -1 : 1;
      var e = (b&0x7f800000)/0x800000-127;
      var c = (b&0x7fffff)/0x800000;
      var re = s*(1+c)*Math.pow(2,e);
      return re;
    }
  }
}
</script>
<style scoped>
a {
  color: #42b983;
}
</style>
